package com.zrrd.learn.chapter07字符串;

/**
 * 字符串常用方法
 *
 * @author wrn
 * @version 1.0
 * @date 2023/7/17 13:29
 */

public class String02 {

    public static void main(String[] args) {

        String s1 = "abc";
        String s2 = "abc";

        String s3 = new String("abc");
        String s4 = new String("abc");

        String s5 = "a" + "b" + "c";

        String s = "c";

        //jdk
        String s6 = "ab" + s;

        String s7 = s6.intern();
        String s8 = s6.intern();

        int[] as = {1, 2, 3};
        int[] as1 = {1, 2, 3};

        //基本类型表示判断值是否相同，引用类型判断是否为同一地址
        System.out.println(as == as1);
        //任何一个java类都有equals方法(用来比较地址是否相同)   全是object（个例）
        System.out.println(as.equals(as1));

        //true 表示s1与s2地址相同
        System.out.println("------><-----");

        System.out.println(s1 == s2);
        System.out.println(s3 == s4);

        //字面值"abc"
        System.out.println(s1.equals(s4));

        System.out.println(s1 == s5);

        //s1指向常量池 s6 由于+和字符串变量 参与 做了优化 StringBuilder(常).append(s)
        System.out.println(s6 == s1);

        System.out.println(s7 == s1);
        System.out.println(s7 == s8);

        //维视
        String s9 = "a".concat("b").concat("c");
        System.out.println(s1 == s9);


        String s10 = "def";
        //实例名{变量名称}.方法()
        System.out.println(s10.charAt(1));

        System.out.println("abcdefghijklmn".indexOf("jk"));//在字符串中找是否有"jk"
        System.out.println("abcdefghijklmn".indexOf("jk",7));//在字符串中从7开始往后找是否有"jk"

        System.out.println("abc".equalsIgnoreCase("ABC"));
        System.out.println("abc".replace("b","**"));

        System.out.println("abcdefghijklmn".substring(3).indexOf("c"));

        System.out.println("abcdefghijklmn".substring(2,3));


    }

}
